﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Script.Serialization;
using RADB;
using System.Collections;

namespace WaiterService
{
    public partial class TableStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/x-javascript";
            IDataTransfer DTO = (IDataTransfer)Application["DTO"];
            JavaScriptSerializer serializer = (JavaScriptSerializer)Application["serializer"];

            string logedin = Request["logedin"];

            if (logedin != "yes")
                return;

            int tableOccupiedID = 0, tableDirtyID = 0;
            if (!int.TryParse(Request["SetTableOccupied"], out tableOccupiedID))
               if (!int.TryParse(Request["SetTableDirty"], out tableDirtyID))
                    return;

            if (tableOccupiedID > 0)
            {
                Hashtable result = new Hashtable();
                result.Add("Success", DTO.setTableOccupied(tableOccupiedID));
                Response.Output.Write("({0})", serializer.Serialize(result));
                return;
            }

            if (tableDirtyID > 0)
            {
                Hashtable result = new Hashtable();
                result.Add("Success", DTO.setTableDirty(tableDirtyID));
                Response.Output.Write("({0})", serializer.Serialize(result));
                return;
            }
        }
    }
}